package com.hjm.project.merchantInfo.newMerRecord.controller;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.merchantInfo.newMerRecord.Service.INewMerRecordService;
import com.hjm.project.merchantInfo.newMerRecord.domain.NewMerRecord;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 新商户迁移Controller
 *
 * @author maker-platform
 * @date 2021-04-01
 */
@Controller
@RequestMapping("/newMerRecord/newMerRecord")
public class NewMerRecordController extends BaseController {
    private String prefix = "merchantInfo/newMerRecord";

    @Resource
    private INewMerRecordService newMerRecordService;

    @RequiresPermissions("newMerRecord:newMerRecord:view")
    @GetMapping()
    public String newMerRecord() {
        return prefix + "/newMerRecord";
    }

    @RequiresPermissions("newMerRecord:newMerRecord:view")
    @GetMapping("/newMerRecordAgent")
    public String newMerRecordAgent() {
        return prefix + "/newMerRecordAgent";
    }

    @RequiresPermissions("newMerRecord:newMerRecord:view")
    @GetMapping("/newMerRecordUpdate")
    public String newMerRecordUpdate() {
        return prefix + "/newMerRecordUpdate";
    }

    /**
     * 查询新商户迁移列表
     *
     * @param newMerRecord
     * @return
     */
    @RequiresPermissions("newMerRecord:newMerRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewMerRecord newMerRecord) {
        startPage();
        List<NewMerRecord> list = newMerRecordService.selectNewMerRecordList(newMerRecord);
        return getDataTable(list);
    }

    /**
     * 导出新商户迁移列表
     */
    @RequiresPermissions("newMerRecord:newMerRecord:export")
    @Log(title = "新商户迁移", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NewMerRecord newMerRecord) {
        List<NewMerRecord> list = newMerRecordService.selectNewMerRecordList(newMerRecord);
        ExcelUtil<NewMerRecord> util = new ExcelUtil<NewMerRecord>(NewMerRecord.class);
        return util.exportExcel(list, "newMerRecord");
    }

    /**
     * 新增新商户迁移
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存商户换机,商户迁移
     */
    @RequiresPermissions("newMerRecord:newMerRecord:add")
    @Log(title = "新商户迁移", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewMerRecord newMerRecord) {
        return toAjax(newMerRecordService.insertNewMerRecord(newMerRecord));
    }

    /**
     * 修改新商户迁移
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id,ModelMap mmap) {
        NewMerRecord newMerRecord = newMerRecordService.selectNewMerRecordById(id);
        mmap.put("newMerRecord", newMerRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存新商户迁移
     */
    @RequiresPermissions("newMerRecord:newMerRecord:edit")
    @Log(title = "新商户迁移", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewMerRecord newMerRecord) {
        return toAjax(newMerRecordService.updateNewMerRecord(newMerRecord));
    }

    /**
     * 删除新商户迁移
     */
    @RequiresPermissions("newMerRecord:newMerRecord:remove")
    @Log(title = "新商户迁移", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(newMerRecordService.deleteNewMerRecordByIds(ids));
    }
}
